package day06;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author zouran
 * createDate：2024/6/29  13:28
 */
public class UdpServer {
    public static void main(String[] args) throws IOException {
        DatagramSocket server = new DatagramSocket(10000);
        System.out.println("这里是服务器，等待接收客户端信息...");
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket serverPacket = new DatagramPacket(bytes, 0, bytes.length);
            server.receive(serverPacket);
            bytes = serverPacket.getData();
            String message = new String(bytes, 0, serverPacket.getLength());
            System.out.println("服务器已接收到信息：" + message);
        }
    }
}
